//package com.hq.xmind.service;
//
//import com.hq.xmind.model.ZNodeTree;
//import net.sf.json.JSONArray;
//import net.sf.json.JsonConfig;
//import net.sf.json.util.CycleDetectionStrategy;
//import org.springframework.stereotype.Service;
//import org.springframework.util.ResourceUtils;
//import org.springframework.util.StringUtils;
//import org.xmind.core.*;
//
//import java.io.File;
//import java.io.IOException;
//import java.util.ArrayList;
//import java.util.List;
//
//@Service
//public class XmindServicebak {
//
//    public String getTreeJson() {
//
//        IWorkbookBuilder builder = Core.getWorkbookBuilder();//初始化builder
//        IWorkbook workbook = null;
//        try {
//            File file = ResourceUtils.getFile("classpath:file/java.xmind");
//            workbook = builder.loadFromPath(file.getAbsolutePath());//打开XMind文件
//        } catch (IOException e) {
//            e.printStackTrace();
//        } catch (CoreException e) {
//            e.printStackTrace();
//        }
//        ISheet defSheet = workbook.getPrimarySheet();//获取主Sheet
//        ITopic rootTopic = defSheet.getRootTopic();//获取根Topic
//        List<ITopic> allChildren = rootTopic.getAllChildren();
//        ZNodeTree treeRoot = new ZNodeTree();
//        treeRoot.setId(rootTopic.getId());
//        treeRoot.setName(rootTopic.getTitleText());
//        treeRoot.setpId("root");
//        treeRoot.setLevel(0);
//        List<ZNodeTree> treeList = new ArrayList<ZNodeTree>();
//        treeList.add(treeRoot);
//        treeTopicList(allChildren, 1, "", "", treeList);
//        JsonConfig jsonConfig = new JsonConfig();
//        jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
//        String json = JSONArray.fromObject(treeList,jsonConfig).toString();
//
//        return json;
//    }
//
//    public static List<ZNodeTree> treeTopicList(List<ITopic> allChildren, int level, String id, String name, List<ZNodeTree> treeList) {
//        for (ITopic topic : allChildren) {
//            if (!StringUtils.isEmpty(id) && !StringUtils.isEmpty(name)) {
//                id = id + ",";
//                name = name + ",";
//            }
//            id = id + topic.getId();
//            name = name + topic.getTitleText();
////            System.out.println(id);
////            System.out.println(name);
////            System.out.println(topic.getTitleText());
//
//            List<ITopic> childrenList = topic.getAllChildren();
//
//            ZNodeTree tree = new ZNodeTree();
//            tree.setId(topic.getId());
//            tree.setParentName(topic.getParent().getTitleText());
//            tree.setpId(topic.getParent().getId());
//            tree.setLevel(level);
//            tree.setName(topic.getTitleText());
//            tree.setPathIds(id);
//            tree.setPathNameList(name);
//            treeList.add(tree);
//            if (childrenList.size() > 0) {
//                treeTopicList(childrenList, level + 1, id, name, treeList);
//            }
//        }
//        return treeList;
//    }
//}
